using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Extensions
{
	public static void Shuffle<T>(this IList<T> list)
	{
		System.Random random = new System.Random();
		int num = list.Count;
		while (num > 1)
		{
			num--;
			int index = random.Next(num + 1);
			T value = list[index];
			list[index] = list[num];
			list[num] = value;
		}
	}

	public static void ForceSetActive(this GameObject rootObject, bool active)
	{
		rootObject.SetActiveRecursively(active);
	}

	public static bool IsNullOrEmpty(this ICollection collection)
	{
		return collection == null || collection.Count <= 0;
	}

	public static IEnumerator FadeToAlpha(this CanvasGroup group, float alpha, float time, AnimationCurve curve = null, Action onCompleteAction = null)
	{
		float currentTime = 0f;
		float initialAlpha = group.alpha;
		while (currentTime < time)
		{
			float evaluatedTime = curve?.Evaluate(currentTime / time) ?? time;
			group.alpha = Mathf.Lerp(initialAlpha, alpha, evaluatedTime);
			currentTime += Time.deltaTime;
			yield return null;
		}
		group.alpha = alpha;
		onCompleteAction.Fire();
	}
}
